package com.guigu.wenzhiyi.controller;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.guigu.aop.OpLog;
import com.guigu.util.service.IDService;
import com.guigu.wenzhiyi.pojo.Mapply;
import com.guigu.wenzhiyi.service.MapplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("Mapply.do")
public class MapplyController {

    @Autowired
    MapplyService mapplyService;
    @Autowired
    IDService idService;

    @RequestMapping("WZYadd")
    @OpLog(opModule = "生产计划管理模块",operType = "新发生生产计划登记",operDesc = "此方法用于生产计划登记")
    public String WZYadd( String lists){
        Gson gson = new Gson();
        List<Mapply> mapplies = gson.fromJson(lists,new TypeToken<List<Mapply>>(){}.getType());
        String id = idService.PMC_ID();
        for (Mapply list : mapplies) {
            list.setApplyid(id);
            mapplyService.insert(list);
        }
        return "/wen_zhi_yi/mApplyAdd.html";
    }

    @RequestMapping("WZYmapplySH")
    @ResponseBody
    public List<Mapply> WZYmapplySH(){
        Mapply mapply = new Mapply();
        mapply.setChecktag("S001-0");
        List<Mapply> mapplies = mapplyService.WZYlist(mapply);

        List<Mapply> list = new ArrayList<>();
        for (Mapply ms : mapplies) {
            if (!ms.getApplyid().equals(mapply.getApplyid())){
                mapply=ms;
                list.add(mapply);
            }
        }
        return list;
    }

    @RequestMapping("WZYSHlist")
    @ResponseBody
    public List<Mapply> WZYSHlist(Mapply mapply){
        return mapplyService.WZY_SH_list(mapply);
    }

    @RequestMapping("WZYSHupdate")
    @OpLog(opModule = "生产计划管理模块",operType = "生产计划审核",operDesc = "此方法用于生产计划审核")
    public String WZYSHupdate(Mapply mapply){
        mapplyService.WZY_SH_update(mapply);
        return "/wen_zhi_yi/mApplySH.html";
    }

    @RequestMapping("WZYmapplyCha")
    @ResponseBody
    public List<Mapply> WZYmapplyCha(Mapply mapply){
        return mapplyService.WZY_Cha(mapply);
    }



}
